﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using CUREBusinessLogicLayer;

namespace CURE.SystemManagement
{
    public partial class Authority : System.Web.UI.Page
    {
        #region 变量
        private string info;

        public string Info
        {
            get { return info; }
            set { info = value; }
        }
        private string groupname;

        public string Groupname
        {
            get { return groupname; }
            set { groupname = value; }
        }
        #endregion

        AuthorityBll authoritybll = new AuthorityBll();
        protected void Page_Load(object sender, EventArgs e)
        {
            info = Request.QueryString["info"];
            groupname = authoritybll.GetGroupNameByInfo(info);
        }

        /// <summary>
        /// 获取模块列表
        /// </summary>
        /// <returns></returns>
        public string getActionList()
        {
            string html = "";
            DataTable dt = default(DataTable);
            dt = authoritybll.getActionList();
            if (dt != null && dt.Rows.Count > 0)
            {
                html += "<div style='margin-top:10px;' layoutH=\"240\"> ";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string id = dt.Rows[i]["ACTION_COLUMNID"].ToString();
                    if (i == 0)
                    {

                        html += "<b>" + dt.Rows[i]["action_columnname"] + "</b></br>";
                        html += "&nbsp;&nbsp;<input type='checkbox' name='c1' value='" + dt.Rows[i]["action"] + "'/>" + dt.Rows[i]["ACTION_NAME"] + "";
                    }
                    else if (dt.Rows[i - 1]["action_columnid"].ToString() == id)
                    {
                        html += "&nbsp;&nbsp;<input type='checkbox' name='c1' value='" + dt.Rows[i]["action"] + "'/>" + dt.Rows[i]["ACTION_NAME"] + "";
                    }
                    else
                    {
                        //html += "<div style='margin-top:10px;'>";
                        html += "<br/><br/><b>" + dt.Rows[i]["action_columnname"] + "</b></br>";
                        html += "&nbsp;&nbsp;<input type='checkbox' name='c1' value='" + dt.Rows[i]["action"] + "'/>" + dt.Rows[i]["ACTION_NAME"] + "";
                    }
                }
                html += "</div>";
            }
            return html;
        }

        /// <summary>
        /// 获取已配置的权限
        /// </summary>
        /// <returns></returns>
        public string getActionStr()
        {
            string actionList = "";
            if (info != null && info != "")
            {
                Dictionary<string, object> dictionry = new Dictionary<string, object>();
                dictionry.Add("info", info);
                DataTable dt = default(DataTable);
                dt = authoritybll.getActionStrByGroupInfo(dictionry);
                if (dt != null && dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        actionList += dt.Rows[i]["action"].ToString() + ",";
                    }
                }
                actionList = actionList.TrimEnd(',');
                return actionList;
            }
            else
            {
                return "";
            }
        }
    }
}
